package com.snails.array;

/**
 * <a href="https://leetcode.cn/problems/remove-element/">27.移除元素</a>
 *
 * @since 2023-04-13
 */
public class LeetCode27 {

    public int removeElement(int[] nums, int val) {
        int n = nums.length;
        int left = 0;
        for (int right = 0; right < n; right++) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left++;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        LeetCode27 leetCode27 = new LeetCode27();
        int[] nums = {0,1,2,2,3,0,4,2};
        int val = 2;
        int i = leetCode27.removeElement(nums, val);
        System.out.println(i);
    }
}
